package cn.com.lookang.robot;

import kotlin.coroutines.CoroutineContext;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.BotFactoryJvm;
import net.mamoe.mirai.event.EventHandler;
import net.mamoe.mirai.event.Events;
import net.mamoe.mirai.event.ListeningStatus;
import net.mamoe.mirai.event.SimpleListenerHost;
import net.mamoe.mirai.message.GroupMessageEvent;
import net.mamoe.mirai.utils.BotConfiguration;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author liulekang
 * @date 2020/7/25
 */
public class Test {

    public static void main(String[] args) {
        final Bot bot = BotFactoryJvm.newBot(3512563919L, "vqpj9589", new BotConfiguration() {
            {
                //保存设备信息到文件
                fileBasedDeviceInfo("deviceInfo.json");
                // setLoginSolver();
                // setBotLoggerSupplier();
            }
        });

        bot.login();

        Events.registerEvents(bot,new SimpleListenerHost() {

            @EventHandler
            public ListeningStatus onGroupMessage(GroupMessageEvent event) {
                String msgString = event.getMessage().contentToString();
                event.getGroup().sendMessage(msgString);
                return ListeningStatus.LISTENING;
            }

            @Override
            public void handleException(CoroutineContext context,  Throwable exception) {
                throw new RuntimeException("在事件处理中发生异常", exception);
            }
        });
        bot.join();
    }
}
